<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="lib/bootstrap.min.css">
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        
        .box {
            width: 800px;
            height: 400px;
            /* background-color: pink; */
            margin: 100px auto;
        }
        
        .list {
            width: 800px;
            padding-left: 25px;
        }
        
        .checkbox,
        .login {
            padding-left: 10px;
        }
        
        .login {
            margin-left: 10px;
            margin-top: 20px;
        }
        
        h2 {
            width: 760px;
            font-weight: normal;
            height: 50px;
            border-bottom: 1px solid #ddd;
            color: #333;
            font-size: 30px;
            margin-left: 15px;
        }
    </style>
</head>

<body>
    <div class="form-horizontal box">
        <h2>
            用户注册
        </h2>
        <div class="form-group list">
            <label for="username">用户名</label>
            <input type="text" class="form-control" id="username" placeholder="请输入用户名">
        </div>
        <div class="form-group list">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" placeholder="请输入密码">
        </div>
        <div class="form-group list">
            <label for="realName">真实姓名</label>
            <input type="text" class="form-control" id="realName" placeholder="请输入姓名">
        </div>
        <div class="form-group">
            <label class="radio-inline">
                <input type="radio" name="type" id="teacher" checked>老师
            </label>
            <label class="radio-inline">
                <input type="radio" name="type" id="student">学生
            </label>
        </div>
        <button class="btn btn-primary registe">注册</button>
    </div>

    <script src="lib/common.js"></script>
    <script src="lib/jquery.min.js"></script>
    <script>
        $(".registe").click(function() {
            let username = $("#username").val();
            let password = $("#password").val();
            let name = $("#realName").val();
            $.ajax({
                url: `${address}/register`,
                data: {
                    username,
                    password,
                    name,
                    userType: $("#teacher")[0].checked ? 0 : 1
                },
                success(data) {
                    if (data === "error") {
                        alert("注册失败")
                    } else {
                        alert("注册成功");
                        location.href = `${address}/login.html`
                    }
                }
            })
        })
    </script>
</body>

</html>